package microcredit.gui.table.impl;

import java.awt.Color;
import java.util.Date;

import javax.swing.ImageIcon;

import microcredit.gui.table.EnumBeanTableModel;
import microcredit.model.Member;
import microcredit.model.domain.Status;

enum MemberColumns {
	NUMBER, 
	NAME, 
	GROUP, 
	STATUS, 
//	RESIDENCE, 
	LAST_UPDATE;
}

public class MemberTableModel extends EnumBeanTableModel<Member, MemberColumns> {

	@Override
	protected String getName(MemberColumns column) {
		switch(column) {
		case NUMBER : return "No";
		case NAME : return "Name";
		case GROUP : return "Group";
		case STATUS : return "Status";
//		case RESIDENCE : return "Residence";
		case LAST_UPDATE : return "Last update";
	}
	return "";
	}
	
	@Override
	protected MemberColumns getSortColumn() {
		return MemberColumns.NAME;
	}
	
	@Override
	protected int getWidth(MemberColumns column) {
		switch(column) {
		case NUMBER : return 60;
		case NAME : return 200;
		case GROUP : return 200;
		case STATUS : return 50;
//		case RESIDENCE : return 200;
		case LAST_UPDATE : return 130;
		}
		return super.getWidth(column);
	}
	
	@Override
	protected Object getValue(Member bean, MemberColumns column) {
		switch(column) {
		case NUMBER : return Member.formatID(bean.getId());
		case NAME : return bean.getFullName();
		case GROUP : return bean.getGroup() != null ? bean.getGroup().getFullName() : "";
		case STATUS : return bean.getStatus().getString();
//		case RESIDENCE : return bean.getResidence();
		case LAST_UPDATE : return bean.getUpdateStamp();
		}
		return null;
	}
	
	@Override
	protected Class<?> getValueClass(MemberColumns column) {
		switch(column) {
//		case RESIDENCE : return bean.getResidence();
		case LAST_UPDATE : return Date.class;
		}
		return String.class;
	}
	
	@Override
	protected Color getForeground(Member m, MemberColumns column) {
		if (m.getStatus() == Status.I) {
			return Color.red;
		} 
		return super.getForeground(m, column);
	}

	@Override
	public ImageIcon getRowIcon() {
		return new ImageIcon(MemberTableModel.class.getResource("/microcredit/icons/x16/id_card.png"));
	}
}